home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / bm_cpio.gz / unixbm.cpio / main.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  18KB  |  792 lines

  1. /*
  2.  *    Simple mail user interface for KA9Q IP/TCP package.
  3.  *    A.D. Barksdale Garbee II, aka Bdale, N3EUA
  4.  *    Copyright 1986 Bdale Garbee, All Rights Reserved.
  5.  *    Permission granted for non-commercial copying and use, provided
  6.  *    this notice is retained.
  7.  *    Copyright 1987 1988 Dave Trulli NN2Z, All Rights Reserved.
  8.  *    Permission granted for non-commercial copying and use, provided
  9.  *    this notice is retained.
  10.  *
  11.  * revision history:
  12.  *
  13.  *  v3.3 870467 D. Trulli nn2z
  14.  *  v3.2 870314 D. Trulli nn2z
  15.  *  v3.1 870117 D. Trulli nn2z
  16.  *    Add multiple arguments mail commands.
  17.  *    Send to multiple users.
  18.  *    Add status commands;
  19.  *  v3.0 871225 D. Trulli nn2z
  20.  *    Heavily restructured program to use a index array of message.
  21.  *    More compatible with UNIX type mail commands.
  22.  *  v2.7 871214 D. Trulli nn2z
  23.  *    Cleaned up header and message parsing to prevent lock up.
  24.  *    Revised command structure.
  25.  *  v2.6 870826 Bdale
  26.  *    integrate PA0GRI's interface/gateway to the WA7MBL PBBS
  27.  *  v2.5 870713 Bdale
  28.  *      integrate additional patches from PA0GRI, minor cleanup
  29.  *  v2.4 870614 - P. Karn
  30.  *      "smart gateway" function moved to smtp client code in net.exe.
  31.  *    User interface for sending mail reworked to resemble Berkeley Mail
  32.  *  v2.3 870524
  33.  *      Extensive addition/revision by Gerard PA0GRI.  Now supports a healthy
  34.  *      set of real commands.  
  35.  *  v2.1,2.2
  36.  *      exact change history lost.
  37.  *  v2.0 c.870115
  38.  *      First version with command parser, only send and quit work.
  39.  *  v1.0
  40.  *      First attempt.  Send messages only.
  41.  */
  42.  
  43. #include <stdio.h>
  44. #include <ctype.h>
  45. #include <string.h>
  46. #include "bm.h"
  47.  
  48. extern char version[];
  49. static char copyright1[] = 
  50. "Copyright 1987 Bdale Garbee, permission granted for non-commercial use.";
  51. static char copyright2[] = 
  52. "Copyright 1988 Dave Trulli NN2Z, permission granted for non-commercial use.";
  53.  
  54. /* comands valid in bm.rc */
  55.  
  56. struct token rccmds[] = {
  57.     "smtp", SMTP,
  58.     "host", HOST,
  59.     "user", USER,
  60.     "edit", EDIT,
  61.     "fullname", NAME,
  62.     "reply", REPLY,
  63.     "maxlet", MAXLET,
  64.     "mbox", MBOX,
  65.     "record", RECORD,
  66.     "screen", SCREEN,
  67.     "folder", FOLDER,
  68.     "mqueue", MQUEUE,
  69.     NULLCHAR, 0
  70. };
  71.  
  72. FILE    *mfile = NULLFILE;
  73. char     *hostname = NULLCHAR;        /* name of this host from rc file */
  74. char    *username = NULLCHAR;        /* name of this user from rc file */
  75. char    *fullname = NULLCHAR;        /* fullname of this user from rc file */
  76. char    *replyto = NULLCHAR;        /* address for reply-to header */
  77. char    *maildir = NULLCHAR;        /* defined mail directory */
  78. char    *mqueue = NULLCHAR;        /* defined mqueue outbound directory */
  79. char    *savebox = NULLCHAR;        /* name of the mbox text file */
  80. char    *record = NULLCHAR;        /* record  outbound mail in this file */
  81. char    *folder = NULLCHAR;        /* directory for saveing read mail */
  82. char    *editor = NULLCHAR;        /* user's favorite text editor */
  83. char    notename[9];            /* name of current notesfile */
  84. char    notefile[SLINELEN];        /* full pathname of mail text file */
  85. char    *mfilename = notefile;    /* pointer to current mbox or mail file -f */
  86. int    current;            /* the current message number */
  87. int    nmsgs;            /* the number of messages in the notesfile */
  88. int    newmsgs;        /* Number of new unread message */
  89. int    change;            /* indicates that the mail file has been
  90.                  * changed in this session */
  91. int    fflag = 0;        /* true if current notesfile is not an mbox */
  92. int    qflag = 0;        /* true if bm is used just to queue files */
  93. unsigned maxlet = NLET+1;    /* max number of messages in mailbox */
  94. int    tty = 0;        /* tells if stdin is a tty */
  95. struct let *mbox;        /* pointer to the array of messages */
  96.  
  97.  
  98. char usage[] = "Usage: bm [-u user] [-f file] \n  or bm [-s subject] [-q] addr .. addr\n";
  99. char badmsg[] = "Invalid Message number %d\n";
  100. char nomail[] = "No messages\n";
  101. char noaccess[] = "Unable to access %s\n";
  102.  
  103. main(argc,argv)
  104. int argc;
  105. char *argv[];
  106. {
  107.     extern int optind;
  108.     extern char *optarg;
  109.     char *subjectline = NULLCHAR;
  110.     long    tmp;
  111.     int    c;
  112.     int    ret;
  113.  
  114. #if    defined(__TURBOC__) || defined(MICROSOFT)
  115.     (void) fclose(stdaux);
  116.     (void) fclose(stdprn);
  117. #endif
  118.  
  119.     loadconfig();
  120.  
  121.     if (qflag == 0 && isatty(fileno(stdin))) {
  122.         /* announce ourselves */
  123.         screen_clear();
  124.         printf(" %s\n%s\n%s\n\n",version,copyright1,copyright2);
  125.         tty = 1;
  126.     } 
  127.  
  128.     current = 1;
  129.     nmsgs = 0;
  130.  
  131.     /* check for important directories */
  132.     if(access(maildir,0)){
  133.         printf(noaccess,maildir);
  134.         exit(1);
  135.     }
  136.     if(access(mqueue,0)){
  137.         printf(noaccess,mqueue);
  138.         exit(1);
  139.     }
  140.     strncpy(notename,username,8);
  141.     notename[8] = '\0';
  142.  
  143.     while ((c = getopt(argc,argv,"u:f:s:q")) != -1) {
  144.         switch(c) {
  145.         case 'f':
  146.             fflag++;
  147.             mfilename = optarg;
  148.             break;
  149.         case 'q':
  150.             qflag++;
  151.             break;
  152.         case 's':
  153.             subjectline = optarg;
  154.             break;
  155.         case 'u':
  156.             strncpy(notename,optarg,8);
  157.             notename[8] = '\0';
  158.             break;
  159.         case '?':
  160.             printf(usage);
  161.             exit(1);
  162.         }
  163.     }
  164.  
  165.     /* set any signal handlers to catch break */
  166.     setsignals();
  167.  
  168.     if(optind < argc){
  169.         dosmtpsend(NULLFILE,&argv[optind],argc-optind,subjectline);
  170.         (void) exit(0);
  171.     }
  172.  
  173.     tmp = (long)maxlet * (long)sizeof(struct let);
  174. #ifdef    MSDOS
  175.     /*
  176.     * Since we are in the dos small model make sure that we
  177.     * don't overflow a unsigned short on the number bytes
  178.     * need for mallloc. If not checked malloc will
  179.     * succeed and we will be trashing ourself in no time.
  180.     */
  181.     if ((tmp & 0xffff0000) ||
  182.         (mbox=(struct let *)malloc((unsigned short)tmp)) == (struct let *)NULL){
  183. #else
  184.     if ((mbox=(struct let *)malloc((unsigned)tmp)) == (struct let *)NULL){
  185. #endif
  186.         fprintf(stderr,
  187.         "Can't allocate memory table for %d messages\n",
  188.             maxlet);
  189.         (void) exit(1);
  190.     }
  191.  
  192.     sprintf(notefile,"%s/%s.txt",maildir,notename);
  193.     if (!fflag && lockit())
  194.         exit(1);
  195.     ret = initnotes();
  196.     if (!fflag)
  197.         rmlock(maildir,notename);
  198.     if (ret != 0)
  199.         exit(1);
  200.     listnotes();
  201.     
  202.     getcommand();
  203.     return 0;
  204. }
  205.  
  206. loadconfig()
  207. {
  208.     FILE    *rcfp;    /* handle for the configuration file */
  209.     char    rcline[LINELEN]; /* buffer for config file reading */
  210.     register char *s,*p;
  211.     int line = 0;
  212.     char runcom[LINELEN];
  213.     char *getenv();
  214.  
  215. #ifdef UNIX
  216.     /* Try $HOME/RUNCOM */
  217.     if ((p = getenv("HOME")) != NULLCHAR)
  218.         sprintf(runcom, "%s/%s", p, RUNCOM);
  219. #else
  220.     /* check for BMRC in the ENV */
  221.     if ((p = getenv("BMRC")) != NULLCHAR)
  222.         strcpy(runcom,p);
  223. #endif
  224.     else
  225.         strcpy(runcom,RUNCOM);
  226.  
  227.     if ((rcfp = fopen(runcom,"r")) == NULLFILE) {    /* open config file */
  228.         printf("Cannot open '%s', check your installation\n",runcom);
  229.         (void) exit(1);
  230.     }
  231.     while (!feof(rcfp)) {
  232.         if (fgets(rcline,LINELEN,rcfp) == NULLCHAR)
  233.             break;
  234.         line++;
  235.         rip(rcline);
  236.         if (*rcline == '\0' || *rcline == ';'|| *rcline == '#')
  237.             continue;
  238.         /* find the argument to the command */
  239.  
  240.         s = rcline;
  241.         /* skip the white space */
  242.         while(*s == ' ' || *s == '\t')
  243.                 s++;
  244.         p = s;
  245.         /* skip the command */
  246.         while(*p && *p != ' ' && *p != '\t')
  247.                 p++;
  248.         /* skip the white space */
  249.         while(*p == ' ' || *p == '\t')
  250.                 p++;
  251.         if (*s == '\0')
  252.             continue;
  253.  
  254.         switch (rc_line_type(s)) {
  255.         case HOST:
  256.             hostname = savestr(p);
  257.             break;
  258.         case USER:
  259.             username = savestr(p);
  260.             break;
  261.         case REPLY:
  262.             replyto = savestr(p);
  263.             break;
  264.         case EDIT:
  265.             editor = savestr(p);
  266.             break;
  267.         case SMTP:
  268.             maildir = savestr(p);
  269.             break;
  270.         case NAME:
  271.             fullname = savestr(p);
  272.             break;
  273.         case MAXLET:
  274.             maxlet = atoi(p)+1;
  275.             break;
  276.         case MBOX:
  277.             savebox = savestr(p);
  278.             break;
  279.         case RECORD:
  280.             record = savestr(p);
  281.             break;
  282.         case SCREEN:
  283. #if    defined(__TURBOC__)
  284.             setvideo(p);
  285. #endif
  286.             break;
  287.         case FOLDER:
  288.             folder = savestr(p);
  289.             break;
  290.         case MQUEUE:
  291.             mqueue = savestr(p);
  292.             break;
  293.         default:
  294.             fprintf(stderr,
  295.             "%s: line %d Invalid command: '%s'\n",
  296.             runcom,line,rcline);
  297.             exit(1);
  298.         }
  299.     }
  300.     (void) fclose(rcfp);
  301.     if(maildir == NULLCHAR)
  302.         maildir = mailspool;
  303.     if(mqueue == NULLCHAR)
  304.         mqueue = mailqdir;
  305.     if(savebox == NULLCHAR)
  306.         savebox = "mbox";
  307.     if(hostname == NULLCHAR) {
  308.         fprintf(stderr,"%s: hostname not set\n",runcom);
  309.         exit(1);
  310.     }
  311.     if(username == NULLCHAR) {
  312.         fprintf(stderr,"%s: username not set\n",runcom);
  313.         exit(1);
  314.     }
  315. }
  316.  
  317. /* return the line_type from a line of the configuration file */
  318. rc_line_type(s)
  319. register char *s;
  320. {
  321.     register struct token *tp;
  322.     for (tp = rccmds; tp->str != NULLCHAR; tp++) {
  323.         if (strncmp(tp->str,s,strlen(tp->str)) == 0)
  324.             return tp->type;
  325.     }
  326.     return (NONE);
  327. }
  328.  
  329. /* replace terminating end of line marker(s) with null */
  330. rip(s)
  331. register char *s;
  332. {
  333.     for (; *s; s++)
  334.         if (*s == '\r' || *s == '\n') {
  335.             *s = '\0';
  336.             break;
  337.         }
  338. }
  339.  
  340. /* copy a string return a pointer to it */
  341. char *
  342. savestr(s)
  343. char *s;
  344. {
  345.     register  char *p;
  346.     p = malloc(strlen(s)+1);
  347.     if (p == NULLCHAR) 
  348.         printf("No more memory\n");
  349.     else
  350.         strcpy(p,s);
  351.     return p;
  352. }
  353.  
  354. dohelp()
  355. {
  356.     screen_clear();
  357.     printf("\n\n");
  358.     printf(" d [msglist]           delete a message\n");
  359.     printf(" m userlist            mail a message\n");
  360.     printf(" s [msglist] [file]    save message in file (default mbox)\n");
  361.     printf(" w [msglist] file      save message in file no header\n");
  362.     printf(" f [msg]               forward message\n");
  363.     printf(" b [msg]               bounce message (remail)\n");
  364.     printf(" r [msg]               reply to a message\n");
  365.     printf(" u [msglst]            undelete a message\n");
  366.     printf(" p [msglst]            print message on printer (DOS only)\n");
  367.     printf(" .                     display current message\n");
  368.     printf(" h                     display message headers in notefile\n");
  369.     printf(" l                     list unsent messages\n");
  370.     printf(" k                     kill unsent messages\n");
  371.     printf(" n [file]              display or change notesfile\n");
  372.     printf(" #                     where # is the number of message to read\n");
  373.     printf(" x                     quit without changing mail file\n");
  374.     printf(" q                     quit\n");
  375.     printf(" ! cmd                 run dos command\n");
  376.     printf(" $                     sync the notefile\n");
  377.     printf(" ?                     print this help screen\n");
  378. }
  379.  
  380.  
  381. /* save a message list in a file in mailbox format */
  382. savemsg(argc,argv)
  383. int argc;
  384. register char *argv[];
  385. {
  386.     register char *savefile;
  387.     int msgnum;
  388.     int    i;
  389.     FILE *tfile;
  390.     char buf[LINELEN];
  391.  
  392.     if (mfile == NULLFILE){
  393.         printf(nomail);
  394.         return;
  395.     }
  396.     if (argc == 0 || isdigit(*argv[argc - 1])) {
  397.         savefile = savebox;
  398.     } else {
  399.         savefile = argv[argc - 1];
  400.         --argc;
  401.         /* if it is just a file name and not a path name then check
  402.         ** for a folder path defined and use that path to
  403.         ** save the file.
  404.         */
  405.         if (strpbrk(savefile,"/\\") == NULLCHAR && folder != NULLCHAR) {
  406.             sprintf(buf,"%s/%s",folder,savefile);
  407.             savefile = buf;
  408.         }
  409.     }
  410.     if ((tfile = fopen(savefile,"a")) == NULLFILE) {
  411.         perror(savefile);
  412.         return;
  413.     }
  414.     if (argc == 0)
  415.         msgtofile(current, tfile, 0);
  416.     else {
  417.         for (i = 0; i < argc; i++) {
  418.             msgnum = atoi(argv[i]);
  419.             if (msgnum >= 1 && msgnum <= nmsgs)
  420.                 msgtofile(msgnum, tfile, 0);
  421.             else
  422.                 printf(badmsg,msgnum);
  423.         }
  424.     }
  425.         (void) fclose(tfile);
  426.         printf("%s appended\n",savefile);
  427. }
  428.  
  429. #ifdef MSDOS
  430. /* send messages to the print device */
  431. printmsg(argc,argv)
  432. int argc;
  433. char *argv[];
  434. {
  435.     FILE *prn;
  436.     int msgnum;
  437.     int    i;
  438.  
  439.     if (mfile == NULLFILE){
  440.         printf(nomail);
  441.         return;
  442.     }
  443.     if ((prn = fopen("PRN","a")) == NULL) {
  444.         perror("PRN");
  445.         return;
  446.     }
  447.     if (argc == 0)
  448.         msgtofile(current, prn, 0);
  449.     else {
  450.         for (i = 0; i < argc; i++) {
  451.             msgnum = atoi(argv[i]);
  452.             if (msgnum >= 1 && msgnum <= nmsgs)
  453.                 msgtofile(msgnum, prn, 0);
  454.             else
  455.                 printf(badmsg,msgnum);
  456.         }
  457.     }
  458.     fclose(prn);
  459. }
  460. #endif
  461.  
  462. writemsg(argc,argv)
  463. int argc;
  464. char *argv[];
  465. {
  466.     char *writefile;
  467.     int msgnum;
  468.     int    i;
  469.     FILE *tfile;
  470.  
  471.     if (mfile == NULLFILE){
  472.         printf(nomail);
  473.         return;
  474.     }
  475.     if (argc == 0 || isdigit(*argv[argc - 1])) {
  476.         printf("no file specified\n");
  477.         return;
  478.     } else {
  479.         writefile = argv[argc - 1];
  480.         --argc;
  481.     }
  482.     if ((tfile = fopen(writefile,"a")) == NULLFILE) {
  483.         perror(writefile);
  484.         return;
  485.     }
  486.     if (argc == 0)
  487.         msgtofile(current, tfile, 1);
  488.     else {
  489.         for (i = 0; i < argc; i++) {
  490.             msgnum = atoi(argv[i]);
  491.             if (msgnum >= 1 && msgnum <= nmsgs)
  492.                 msgtofile(msgnum, tfile, 1);
  493.             else
  494.                 printf(badmsg,msgnum);
  495.         }
  496.     }
  497.     (void) fclose(tfile);
  498.     printf("%s appended\n",writefile);
  499. }
  500.  
  501. bmexit(x)
  502. int x;
  503. {
  504.     if(!fflag && lockit())
  505.         exit(1);
  506.     (void) closenotes();
  507.     if (!fflag)
  508.         rmlock(maildir,notename);
  509.     exit(x);
  510. }
  511.  
  512. /* this is the main command processing loop */
  513. getcommand()
  514. {
  515.     FILE *tfile, *tmpfile();
  516.     char    command[LINELEN];    /* command line */
  517.     char    *args[MAXARGS];
  518.     int    nargs;
  519.     char    *cp;
  520.     register int    msgnum;
  521.     register int    i;
  522.     int ret;
  523.  
  524.     printf("\nType ? for help.\n");
  525.  
  526.     /* command parsing loop */
  527.     while(1) {
  528.         printf("\"%s\"> ",notename);
  529.         gets(command);
  530.  
  531.         if (feof(stdin))        /* someone hit ^Z! */
  532.             strcpy(command,"q");    /* treat it like 'q' */
  533.             
  534.         if(*command == '!') {
  535.             if (system(&command[1]))
  536.                 perror("system");
  537.             continue;
  538.         }
  539.         if (*command) {
  540.             cp = command;
  541.             while (*cp && *cp != ' ')
  542.                 cp++;
  543.             nargs = parse(cp,args,MAXARGS);
  544.         }
  545.  
  546.         switch (*command) {
  547.         case 'm':        /* send msg */
  548.             if (nargs == 0) {
  549.                 printf("To: ");
  550.                 gets(command);
  551.                 nargs = parse(command,args,MAXARGS);
  552.             }
  553.             dosmtpsend(NULLFILE,args,nargs,NULLCHAR);
  554.             break;
  555.  
  556.         case 's':        /* save current msg to file */
  557.             savemsg(nargs,args);
  558.             break;
  559.  
  560.         case 'w':        /* write current msg to file */
  561.             writemsg(nargs,args);
  562.             break;
  563.  
  564.         case 'x':        /* abort */
  565.             (void) fclose(mfile);
  566.             (void) exit(0);
  567.             /* NOTREACHED */
  568.             break;
  569.  
  570.         case 'p':        /* print message */
  571. #ifdef MSDOS
  572.             printmsg(nargs,args);
  573. #else
  574.             printf("Command not available in this version\n");
  575. #endif
  576.             break;
  577.  
  578.         case 'r':            /* reply */
  579.             if (nargs == 0)
  580.                 msgnum = current;
  581.             else
  582.                 msgnum = atoi(args[0]);
  583.             if (msgnum >= 1 && msgnum <= nmsgs)
  584.                 reply(msgnum);
  585.             else
  586.                 printf(badmsg,msgnum);
  587.             break;
  588.  
  589.         case 'f':
  590.             if(nargs == 0)
  591.                 msgnum = current;
  592.             else 
  593.                 msgnum = atoi(args[0]);
  594.             if (msgnum < 1 || msgnum > nmsgs) {
  595.                 printf(badmsg,msgnum);
  596.                 break;
  597.             }
  598.             if((tfile = tmpfile()) == NULLFILE)
  599.                 printf("\nCannot open temp file\n");
  600.             else {
  601.                 msgtofile(msgnum,tfile,0);
  602.                 fseek(tfile,0L,0);
  603.                 printf("To: ");
  604.                 gets(command);
  605.                 nargs = parse(command,args,MAXARGS);
  606.                 dosmtpsend(tfile,args,nargs,NULLCHAR);
  607.                 (void) fclose(tfile);
  608.             }
  609.             break;
  610.  
  611.         case 'b':        /* bounce a message */
  612.             if(nargs == 0)
  613.                 msgnum = current;
  614.             else 
  615.                 msgnum = atoi(args[0]);
  616.             if (msgnum < 1 || msgnum > nmsgs) {
  617.                 printf(badmsg,msgnum);
  618.                 break;
  619.             }
  620.             if((tfile = tmpfile()) == NULLFILE)
  621.                 printf("\nCannot open temp file\n");
  622.             else {
  623.                 msgtofile(msgnum,tfile,0);
  624.                 fseek(tfile,0L,0);
  625.                 printf("To: ");
  626.                 gets(command);
  627.                 nargs = parse(command,args,MAXARGS);
  628.                 bouncemsg(tfile,args,nargs);
  629.                 (void) fclose(tfile);
  630.             }
  631.             break;
  632.  
  633.         case 'u':
  634.             if (nargs == 0)
  635.                 mbox[current].status &= ~DELETE;
  636.             else
  637.                 for (i = 0; i < nargs; i++) {
  638.                     msgnum = atoi(args[i]);
  639.                     if( msgnum >= 1 && msgnum <= nmsgs)
  640.                         mbox[msgnum].status &= ~DELETE;
  641.                     else
  642.                         printf(badmsg,msgnum);
  643.                 }
  644.             break;
  645.  
  646.         case 'l':        /* display unsent messages */
  647.             listqueue();
  648.             break;
  649.         case 'k':
  650.             if (nargs == 0)
  651.                 printf("No job id specified\n");
  652.             else
  653.                 for (i = 0; i < nargs; i++) 
  654.                     killjob(args[i]);
  655.             break;
  656.  
  657.         case 'n':     /* display or change notefiles */
  658.             mboxnames(nargs,args);
  659.             break;
  660.         case 'q':        /* quit */
  661.             if (isnewmail()) {
  662.                 printf("New mail has arrived\n");
  663.                 reinit();
  664.             } else
  665.                 bmexit(0);
  666.             /* NOTREACHED */
  667.             break;
  668.         case '$':
  669.             reinit();
  670.             break;
  671.  
  672.         case 'd':        /* delete a message */
  673.             if (nargs == 0)
  674.                 delmsg(current);
  675.             else
  676.                 for ( i = 0; i < nargs; i++) {
  677.                     msgnum = atoi(args[i]);
  678.                     if( msgnum >= 1 && msgnum <= nmsgs)
  679.                         delmsg(msgnum);
  680.                     else
  681.                         printf(badmsg,msgnum);
  682.                 }
  683.             break;
  684.  
  685.         case 'h':        /* list message headers in notesfile */
  686.  
  687.             listnotes();
  688.             break;
  689.  
  690.         case '\0':    /* a blank line prints next message */
  691.             printnext();
  692.             break;
  693.  
  694.         case '?':        /* help */
  695.             dohelp();
  696.             break;
  697.  
  698.         case  '.':
  699.             displaymsg(current);
  700.             break;
  701.         default:
  702.             if (!isdigit(*command))
  703.                 printf("Invalid command - ? for help\n");
  704.             else {
  705.                 msgnum = atoi(command);
  706.                 if (msgnum < 0 || msgnum > nmsgs)
  707.                     printf(badmsg,msgnum);
  708.                 else {
  709.                     current = msgnum;
  710.                     displaymsg(current);
  711.                 }
  712.             }
  713.             break;
  714.         }
  715.     }
  716. }
  717.  
  718. /* list or change mbox */
  719. mboxnames(argc,argv)
  720. int argc;
  721. char *argv[];
  722. {
  723.     register char *cp;
  724.     int ret;
  725.     char    line[80];
  726.     char    buf[LINELEN];
  727.  
  728.     if(argc != 0) {
  729.         if(!fflag && lockit())
  730.             return;
  731.         ret = closenotes();
  732.         if (!fflag)
  733.             rmlock(maildir,notename);
  734.             if (ret != 0)
  735.                 exit(1);
  736.             if (strpbrk(argv[0],"/\\") != NULLCHAR) {
  737.                 fflag = 1;
  738.                 mfilename = argv[0];
  739.             } else {
  740.                 fflag = 0;
  741.                 mfilename = notefile;
  742.                 strncpy(notename,argv[0],8);
  743.                 notename[8] = '\0';
  744.                 sprintf(notefile,"%s/%s.txt",maildir,notename);
  745.             }
  746.             if (!fflag && lockit()) {
  747.                 mfile = NULLFILE;
  748.                 printf("Mail file is busy\n");
  749.                 return;
  750.             }
  751.             ret = initnotes();
  752.             if (!fflag)
  753.                 rmlock(maildir,notename);
  754.             if (ret != 0)
  755.                 exit(1);
  756.             listnotes();
  757.  
  758.         } else {  /* he wants to see what notefiles there are */
  759.             sprintf(buf,"%s/*.txt",maildir,notename);
  760.             filedir(buf,0,line);
  761.             while(line[0] != '\0') {
  762.                 cp = strchr(line,'.');
  763.                 *cp = '\0';
  764.                 printf("notesfile -> %s\n",line);
  765.                 filedir(buf,1,line);
  766.             }
  767.         }
  768. }
  769.  
  770. reinit()
  771. {
  772.     int ret;
  773.     if (!fflag && lockit())
  774.         return;
  775.     ret = closenotes();
  776.     if (!fflag)
  777.         rmlock(maildir,notename);
  778.     if (ret != 0)
  779.         exit(1);
  780.     if (!fflag && lockit()) {
  781.         mfile = NULLFILE;
  782.         printf("Mail file is busy\n");
  783.         return;
  784.     }
  785.     ret = initnotes();
  786.     if (!fflag)
  787.         rmlock(maildir,notename);
  788.     if (ret != 0)
  789.         exit(1);
  790.     listnotes();
  791. }
  792.